﻿using NLog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace Susha.Models.Helpers
{
    public static class CommonRepository
    {
        private static Logger _logger = LogManager.GetCurrentClassLogger();

        public static void DeletePhoto(String photo)
        {
            if (String.IsNullOrEmpty(photo)
                || photo.Equals("default.jpg")
                || photo.Equals("001.jpg")
                || photo.Equals("002.jpg")
                || photo.Equals("003.jpg")
                || photo.Equals("004.jpg")
                || photo.Equals("005.jpg")
                || photo.Equals("006.jpg"))
                return;

            String photoPath = String.Format("{0}{1}", CommonTools.PATH_PHOTOS, photo);
            try
            {
                if (File.Exists(photoPath))
                {
                    File.Delete(photoPath);
                    _logger.Info(String.Format("Удалена фотография {0}", photo)); //"Photo {0} was deleted;"
                }
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
            }
        }
    }
}